package atmv3;

import java.util.*; 

class ATMv3 {
   List<Integer> banknotes = new ArrayList<Integer>(); 

   ATMv3(int[] ourBanknotes){
       
        int[] tempBanknotes = ourBanknotes.clone();
        Arrays.sort(tempBanknotes);
        
        int temp = tempBanknotes[0];
        for(int i = 0; i < tempBanknotes.length; i++){
            if( (tempBanknotes[i] >= 0) && 
                    ((banknotes.isEmpty()) | (tempBanknotes[i] != temp))){
                temp = tempBanknotes[i];
                banknotes.add(temp);                
            }  
        }  
    }
   
    public ArrayList<int[]> cashing(int sum){        
        ArrayList<int[]> myVariants = new ArrayList<int[]>();
        cashing(sum, banknotes.size() - 1, new int[banknotes.size()], myVariants);     
        return myVariants;
    }    
    
    public void cashing(int sum, int banknoteNum, int[] takenBanknotes, ArrayList<int[]> myVariants){        
        if(sum == 0)
            myVariants.add(takenBanknotes);
        else{
            if(banknoteNum >= 0)
                for(int i = 0; sum >= 0;i++){
                    cashing(sum, banknoteNum-1, takenBanknotes.clone(), myVariants); 
                    takenBanknotes[banknoteNum]++;
                    sum -= banknotes.get(banknoteNum);
                }  
        }
    }
    
}//ATM
